#ifndef MESSAGE_QUEUE_H
#define MESSAGE_QUEUE_H

#include "message.h"
//#include "process_management.h"

#define MAX_LENGTH_QUEUE 20

/* message queue possible status */
#define NOT_WAITING 0
#define WAITING_FIRST 1
#define WAITING_PRIORITY 2
#define WAITING_FROM 3

/* type definition */

typedef struct{
  message queue[MAX_LENGTH_QUEUE];
  int32_t count;
  int32_t status;
  int32_t status_data; //tells us the value the process is waiting for
}message_queue;


/* function definitions */

/* insert the message mess in the queue m_queue. Returns 1 in case of success, 0 otherwise */
int32_t insert_message(message_queue* m_queue, message mess);

/* returns the first message and removes it from the queue.Returns 1 if a message is found, 0 otherwise. */
int32_t get_message_first(message_queue* m_queue, message* mess);

/* returns the first message sent by from and removes it from the queue.Returns 1 if a message is found, 0 otherwise.*/
int32_t get_message_from(message_queue* m_queue, int32_t from, message* mess);

/* returns the first message with the correct priority and removes it from the queue. Returns 1 if a message is found, 0 otherwise. */
int32_t get_message_priority(message_queue* m_queue, int32_t priority, message* mess);

/* removes the i:th message from the queue m_queue. Returns 1 if success, 0 otherwise. */
int32_t remove_message(message_queue* m_queue, int32_t i);

/* sets the status information of the message queue m_queue and blocks the process */
void set_status_information(message_queue* m_queue, int32_t status, int32_t status_data);

/* checks if the arrival of the message pointed by mess should wake the process to up */
int32_t wake_me_up(message_queue* m_queue,message* m);

/* returns the number of messages in this queue */
int32_t message_queue_get_count(message_queue* m_queue);

#endif
